extern "C"
{
#include "FFmpegVideoDecoder.h"
#include "ffmpeg_base.h"
}

#include <stdio.h>
#include <iostream>
#include <fstream>

using namespace std;


int main()
{
	int ret = FFmpeg_H264DecoderInit();
	if (ret != 0)
		return 0;

	ifstream ifs;
	ifs.open("/home/lion/Desktop/WebRTCDemo/test_so_lib/build/video_stream.mkv",ios::in | ios::binary);
	if( !ifs.is_open() )
	{
		cout << "文件打开失败" << endl;
		return 0;
	}
	ifs.seekg(0, std::ios::end);
	size_t size = ifs.tellg();
	ifs.seekg(0, std::ios::beg);
	char *buf = (char *)malloc(size);
	ifs.read(buf, size);

	// FILE *f = fopen("video_stream.mkv", "rb");
	// fseek(f, 0, SEEK_END);
	// long fsize = ftell(f);
	// fseek(f, 0, SEEK_SET);

	
	// fread(buf, fsize, 1, f);
	// fclose(f);

	int frameInfo[5];
	uint8_t *rgbBuf = (uint8_t *)malloc(640 * 480 * 3);
	uint8_t *yunBuf;
	FFmpeg_H264Decode((uint8_t*)buf, size, frameInfo, rgbBuf, nullptr);
	// uint8_t r = 0;
	// for(int i = 0; i < size; i++)
	// {
	// 	r = buf[i];
	// }

	// for(int i = 0; i < 640 * 480 * 3; i++)
	// {
	// 	r = rgbBuf[i];
	// }


	save_image("./test.jpg", rgbBuf, 640, 480);

	free(rgbBuf);
	free(buf);
	FFmpeg_VideoDecoderRelease();
	return 0;
}